package com.twu.biblioteca.Models;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * Created by ubuntu on 5/2/14.
 */
public class Data {

    private User loggedInUser;
    private ArrayList<User> users = new ArrayList<>();
    private HashMap<Class<?>,List<? extends Item>> libraryItemLists = new HashMap<>();

    public <T extends Item> void addNewListToLibraryItemLists(Class<T> classType) {
        if (libraryItemLists.get(classType)==null) {
            libraryItemLists.put(classType,new ArrayList<T>());
        }
    }

    public <T extends Item> ArrayList<T> getLibraryItemLists(Class<T> classType) {
        return (ArrayList<T>) libraryItemLists.get(classType);
    }

    public Iterator<User> getUserIterator() {
        return users.iterator();
    }

    public void setLoggedInUser(User loggedInUser) {
        this.loggedInUser = loggedInUser;
    }

    public User getLoggedInUser() {
        return loggedInUser;
    }

    public void addUser(User user) {
        users.add(user);
    }


    public User searchUserById(String userId) {
        Iterator<User> usersIterator = users.iterator();
        while(usersIterator.hasNext()) {
            User currentUser = usersIterator.next();
            if(currentUser.getId().equals(userId))
                return currentUser;
        }
        return null;
    }

}
